package cn.com.yusys.yusp.admin.web.rest;

import cn.com.yusys.yusp.admin.bean.AdminSmNoticeBean;
import cn.com.yusys.yusp.admin.domain.AdminSmNotice;
import cn.com.yusys.yusp.admin.service.AdminSmNoticeServiceImpl;
import cn.com.yusys.yusp.admin.service.RoleProviderService;
import cn.com.yusys.yusp.commons.mapper.QueryModel;
import cn.com.yusys.yusp.commons.service.CommonService;
import cn.com.yusys.yusp.commons.util.StringUtil;
import cn.com.yusys.yusp.commons.web.rest.CommonResource;
import cn.com.yusys.yusp.commons.web.rest.dto.ResultDto;
import cn.com.yusys.yusp.notice.dto.AdminSmNoticeDTO;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * @项目名称: yusp-admin
 * @类名称: AdminSmNoticeResource
 * @类描述: 系统公告
 * @功能描述: 
 * @创建人: liaoxd@yusys.com.cn
 * @创建时间: 2018-01-04 16:44
 * @修改备注: 
 * @修改记录: 修改时间    修改人员    修改原因
 * -------------------------------------------------------------
 * @version 1.0.0
 * @Copyright (c) 2018宇信科技-版权所有
 */
@RestController
@RequestMapping("/api/adminsmnotice")
public class AdminSmNoticeResource extends CommonResource<AdminSmNoticeDTO, String> {

	@Autowired
	private AdminSmNoticeServiceImpl adminSmNoticeService;
	
	@Autowired
	RoleProviderService roleProviderService;

	private final Logger log = LoggerFactory.getLogger(AdminSmNoticeResource.class);

	@Override
	protected CommonService getCommonService() {
		return this.adminSmNoticeService;
	}

	
	
	/**
	* @方法名称: createInfo
	* @方法描述: 新增公告、公告内容并返回ID
	* @参数与返回说明: 
	* @算法描述: 
	*/
    @PostMapping("/createinfo")
    protected ResultDto<AdminSmNoticeBean> createInfo(@RequestBody AdminSmNoticeBean t)
            throws Exception {
        log.debug("REST request to save Object : {}", t);

        AdminSmNoticeBean adminSmNotice = this.adminSmNoticeService.insertInfo(t);

        return new ResultDto<AdminSmNoticeBean>(adminSmNotice);
    }

	
	/**
	* @方法名称: deleteMult
	* @方法描述: 多个删除
	* @参数与返回说明: 
	* @算法描述: 
	*/
	@PostMapping("/deletes/{ids}")
	public ResultDto<Integer> deleteMult(@PathVariable String ids) {
		log.debug("REST request to delete Object : {}", ids);
		String[] id = ids.toString().split(",");
		int i;
		for (i = 0; i < id.length; i++) {
			this.adminSmNoticeService.deleteByPrimaryKey(id[i]);
		}
		int result = i;
		return new ResultDto<Integer>(result);

	}

	
	/**
	* @方法名称: updateSelective
	* @方法描述: 修改接口
	* @参数与返回说明: 
	* @算法描述: 
	*/
	@PostMapping("/updates")
	public ResultDto<Integer> updateSelective(@RequestBody AdminSmNoticeBean t) throws Exception {
		log.debug("REST request to update Object : {}", t);

		int result = this.adminSmNoticeService.updateInfo(t);

		return new ResultDto<Integer>(result);
	}
	
	/**
	* @方法名称: pubNotices
	* @方法描述: 发布通知
	* @参数与返回说明: 
	* @算法描述: 
	*/
	@PostMapping("/pubnotices")
	public ResultDto<Integer> pubNotices(@RequestBody List<AdminSmNotice> t) throws Exception {
		log.debug("REST request to update Object : {}", t);

		int result = this.adminSmNoticeService.pubNotice(t);

		return new ResultDto<Integer>(result);
	}
	
	
	/**
	* @方法名称: readNotices
	* @方法描述: 阅读通知记录
	* @参数与返回说明: 
	* @算法描述: 
	*/
	@PostMapping("/reads")
	public ResultDto<Integer> readNotices(@RequestBody List<AdminSmNoticeBean> t) throws Exception {
		log.debug("REST request to update Object : {}", t);
		
		int result = this.adminSmNoticeService.readNotice(t);

		return new ResultDto<Integer>(result);
	}

	
	/**
	* @方法名称: getNoticeByNoticId
	* @方法描述: 查询公告详情，包含接收对象与富文本内容
	* @参数与返回说明: 
	* @算法描述: 
	*/
	@GetMapping("/noticeinfo/{noticeId}")
    public ResultDto<Map<String,String>> getNoticeByNoticId(@PathVariable String noticeId) {
        log.debug("REST request to query index : {}", noticeId);

        List<Map<String,String>> list = this.adminSmNoticeService.getNoticeByNoticeId(noticeId);

        return new ResultDto<Map<String,String>>(list.get(0));
    }
	
	
	/**
	* @方法名称: findRolesByOrgIds
	* @方法描述: 查询角色列表
	* @参数与返回说明: 
	* @算法描述: 
	*/
	@GetMapping("/roles")
    public ResultDto<List<Map<String,Object>>> findRolesByOrgIds(QueryModel queryModel) {
        
        List<Map<String,Object>> list = roleProviderService.findRolesByOrgIds(queryModel);

        return new ResultDto<List<Map<String,Object>>>(list);
    }
	/**
	* @方法名称: getFileIds
	* @方法描述: 获取公告附件IDS
	* @参数与返回说明: 
	* @算法描述: 
	*/
	@GetMapping("/fileIds")
    public ResultDto<String> getFileIds(QueryModel queryModel) {
        
        String fileIds = this.adminSmNoticeService.getFileIds(queryModel);

        return new ResultDto<String>(fileIds);
    }

	
	/**
	* @方法名称: getUuid
	* @方法描述: 生成公告ID
	* @参数与返回说明: 
	* @算法描述: 
	*/
	@GetMapping("/createNoticeId")
    public ResultDto<String> getUuid() {
        return new ResultDto<String>(StringUtil.getUUID());
    }
	
	@PostMapping("/noticeinsert")
    public int noticeInsert(@RequestBody AdminSmNoticeDTO adminSmNoticeDto) {
	    return this.adminSmNoticeService.noticeInsert(adminSmNoticeDto);
    }
	
}
